<%@ page language="java" contentType="text/html; charset=UTF8" pageEncoding="UTF8"%>
<%@ page import="java.util.*" %>
<%@ page import="bcnet.service.PriceHistoryService" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
	String code = request.getParameter("code");
	String fromYear = request.getParameter("fromYear");
	String fromMonth = request.getParameter("fromMonth");
	String fromDate = request.getParameter("fromDate");
	String toYear = request.getParameter("toYear");
	String toMonth = request.getParameter("toMonth");
	String toDate = request.getParameter("toDate");
	
	Date todayDate = new Date();
	SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
	SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");
	SimpleDateFormat sdfDate = new SimpleDateFormat("dd");
	int toMonthInt = Integer.parseInt(sdfMonth.format(todayDate));
	toMonthInt--;
	String toMonthString = String.format("%02d", toMonthInt);
	
	if(code == null || fromYear == null){
		
	}
	else {
		PriceHistoryService priceHistoryService = new PriceHistoryService();
		priceHistoryService.addPriceHistoryMass( code,  fromYear,  fromMonth,  fromDate,  toYear,  toMonth,  toDate);
		response.sendRedirect("index.jsp");
	}

%>

<form action="addPriceMass.jsp" method="post">
 		<label style="font-size:22px;">Add price</label>
 		<br/>
        <label for="code">Code:</label>  
        <input type="text" id="code" name="code" placeholder="code" value="<%=code%>" required autofocus >
        <br/>
        <label for="code">From:</label>  
        <input type="text" id="fromYear" name="fromYear" placeholder="fromYear" value="2013" required >
        <input type="text" id="fromMonth" name="fromMonth" placeholder="fromMonth" value="00" required >
        <input type="text" id="fromDate" name="fromDate" placeholder="fromDate" value="01" required >
        <br/>
        <label for="code">To:</label>  
        <input type="text" id="toYear" name="toYear" placeholder="toYear" value="<%=sdfYear.format(todayDate)%>" required >
        <input type="text" id="toMonth" name="toMonth" placeholder="toMonth" value="<%=toMonthString%>" required >
        <input type="text" id="toDate" name="toDate" placeholder="toDate" value="<%=sdfDate.format(todayDate)%>" required >
		<button type="submit">Update</button>  
	 </form>  
